//? 还有一种方式见第一次实现(更准确)
//? 思路就是记录每个值的出现次数 要首先弄到max和min
function countSort(arr) {
    let max = -Infinity
    let min = Infinity
    let res = []
    for (let i = 0;i < arr.length; i++) {
        if (arr[i] > max) max = arr[i]
        if (arr[i] < min) min = arr[i]
    }
    let len = max - min + 1
    let countArr = new Array(len).fill(0)
    for (let i = 0; i < arr.length; i ++) {
        countArr[arr[i] - min] += 1
    }
    for (let i = 0; i < countArr.length; i++) {
        let count = countArr[i]
        while (count) {
            res.push(min + i)
            count--
        }
    }
    return res
}



const arr = [3,5,1,2,8,2,10]
console.log(countSort(arr))
